package com.future;

import java.util.HashMap;
import java.util.Map;

/**
 * Description: 205. 同构字符串
 *
 * @author weiruibai.vendor
 * Date: 2023/2/22 09:42
 */
public class Solution_205 {

    private static Solution_205 instance = new Solution_205();

    public static void main(String[] args) {
        String s = "egg";
        String t = "add";
        s = "foo";
        t = "bar";
        System.out.println(instance.isIsomorphic(s, t));
    }

    public boolean isIsomorphic(String s, String t) {
        int N = s.length();
        Map<Character, Character> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            Character cha1 = s.charAt(i);
            Character cha2 = t.charAt(i);
            Character cha3 = map.get(cha1);
            if (cha3 == null) {
                if (map.values().contains(cha2)) {
                    return false;
                }
                map.put(cha1, cha2);
            } else {
                if (cha3 != cha2) {
                    return false;
                }
            }
        }
        return true;
    }
}
